import { Nodes } from '@knno/dom';
import { JSXProps } from '@knno/dom/jsx';
import { Datebox as UIDatebox } from '../components/datebox/datebox';
import { AttrCheck, isArray, isBool, isDate, isStr, jsxBuild } from './utils';
import { DateValue } from '../components/calendar/calendar';
import type { DateMode } from '../components/datePicker/datePicker';

export { UIDatebox };

interface CheckboxProps extends JSXProps<UIDatebox> {
	mode?: DateMode;
	range?: boolean;
	roller?: boolean;
	clearable?: boolean;
	prefixIcon?: string;
	value?: DateValue | DateValue[];
	placeholder?: string;
	disabled?: boolean;
	invalid?: boolean;
}

const ATTRS: AttrCheck = {
	mode: isStr,
	range: isBool,
	roller: isBool,
	clearable: isBool,
	prefixIcon: isStr,
	value: (v) => isDate(v) || isStr(v) || isArray(v),
	placeholder: isStr,
	disabled: isBool,
	invalid: isBool,
};

export function Datebox(props: CheckboxProps, children: Nodes[]): UIDatebox {
	return jsxBuild(new UIDatebox(), props, children, ATTRS);
}
